<?php

class m111005_074601_account_manage extends CDbMigration {
	public function safeUp() {
		$this->addColumn('erp_user_access', 'accountManage', 'boolean');
		$this
			->insert('erp_auth_item',
				array(
					'name' => 'accountManage',
					'type' => CAuthItem::TYPE_ROLE,
					'bizrule' => 'return AccessControl::check("accountManage");',
				));
		$this
			->insert('erp_auth_item_child',
				array(
					'parent' => 'employee',
					'child' => 'accountManage',
				));

		$this->addColumn('erp_user_access', 'accountView', 'boolean');
		$this
			->insert('erp_auth_item',
				array(
					'name' => 'accountView',
					'type' => CAuthItem::TYPE_ROLE,
					'bizrule' => 'return AccessControl::check("accountView");',
				));
		$this
			->insert('erp_auth_item_child',
				array(
					'parent' => 'employee',
					'child' => 'accountView',
				));
	}

	public function safeDown() {
		$this
			->delete('erp_auth_item_child',
				array(
					'and',
					'parent=:parent',
					'child=:child',
				), array(
					':parent' => 'employee',
					':child' => 'accountManage',
				));
		$this
			->delete('erp_auth_item', 'name=:name', array(
				':name' => 'accountManage',
			));
		$this->dropColumn('erp_user_access', 'accountManage');

		$this
			->delete('erp_auth_item_child',
				array(
					'and',
					'parent=:parent',
					'child=:child',
				), array(
					':parent' => 'employee',
					':child' => 'accountView',
				));
		$this
			->delete('erp_auth_item', 'name=:name', array(
				':name' => 'accountView',
			));
		$this->dropColumn('erp_user_access', 'accountView');

	}
}
